//
//  ViewController.m
//  testZhengShu
//
//  Created by Garlic on 2020/3/10.
//  Copyright © 2020 garlic. All rights reserved.
//

#import "ViewController.h"
#import "MyLayout.h"
#import "MyCollectionViewCell.h"

@interface ViewController ()<MyCustomProtocol, UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) MyLayout *myLayout;
@property (nonatomic, strong) NSDictionary *dataDict;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataDict = @{ @"NSObject" : @[@"NSLayoutConstraint", @"NSLayoutManager", @{@"NSParagraphStyle":@[@"NSMutableParagraphStyle"]}]};
    
    [self.view addSubview:self.collectionView];
    
    [self.collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"MyCollectionViewCell"];
}

- (NSInteger)numRowsForClassAndChildrenAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 2) {
        return 1;
    }
    if (indexPath.section == 1 && indexPath.row == 1){
        return 2;
    }
    if (indexPath.section == 1 && indexPath.row == 2){
        return 2;
    }
     return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 2) {
        return 4;
    }else if (section == 1){
        return 6;
    }else{
        return 1;
    }
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor orangeColor];
    cell.label.text = [NSString stringWithFormat:@"%zd---%zd",indexPath.section, indexPath.row];
    return cell;
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.myLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
    }
    return _collectionView;
}

- (MyLayout *)myLayout{
    if (!_myLayout) {
        _myLayout = [MyLayout new];
        _myLayout.customDataSource = self;
        
    }
    return _myLayout;
}

@end
